package org.wang.generalcode.modules.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wang.generalcode.modules.exam.pojo.entity.GradeInfoEntity;
import org.wang.generalcode.modules.exam.pojo.param.GradeInfoParams;
import org.wang.generalcode.modules.exam.pojo.vo.GradeInfoVO;
import org.wang.generalcode.modules.exam.service.GradeInfoService;
import org.wang.generalcode.support.mybaties.Condition;
import org.wang.generalcode.support.mybaties.Query;
import org.wang.generalcode.support.result.PageResult;
import org.wang.generalcode.support.result.Result;
import org.wang.generalcode.support.utils.Func;

import java.util.List;

/**
 * 年级信息表前端控制层
 *
 * @author wz
 * @since 2024-11-20
 */
@Tag(name = "年级信息表接口")
@RestController
@RequestMapping("wang/grade_info")
@RequiredArgsConstructor
public class GradeInfoController {

    private final GradeInfoService gradeinfoService;

    @Operation(summary = "年级信息表分页列表")
    @GetMapping("/page")
    public PageResult<GradeInfoVO> getGradeInfoPage(GradeInfoParams queryParams, Query query) {
        IPage<GradeInfoVO> result = gradeinfoService.getGradeInfoPage(Condition.getPage(query), queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "年级信息表列表")
    @GetMapping("/list")
    public Result getGradeInfoList(GradeInfoParams queryParams) {
        List<GradeInfoVO> result = gradeinfoService.getGradeInfoList(queryParams);
        return Result.success(result);
    }

    @Operation(summary = "新增年级信息表")
    @PostMapping("/save")
    public Result saveGradeInfo(@RequestBody @Valid GradeInfoEntity formData) {
        boolean result = gradeinfoService.save(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取年级信息表表单数据")
    @GetMapping("/detail")
    public Result<GradeInfoEntity> getGradeInfoForm(
            @Parameter(name = "主键", required = true) @RequestParam Long id
    ) {
        GradeInfoEntity formData = gradeinfoService.getById(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改年级信息表")
    @PutMapping(value = "/update")
    public Result updateGradeInfo(
            @RequestBody GradeInfoEntity entity
    ) {
        boolean result = gradeinfoService.updateById(entity);
        return Result.judge(result);
    }

    @Operation(summary = "删除年级信息表")
    @DeleteMapping("/remove")
    public Result deleteGradeInfos(
            @Parameter(name = "主键集合", required = true) @RequestParam String ids
    ) {
        boolean result = gradeinfoService.removeBatchByIds(Func.toLongList(ids));
        return Result.judge(result);
    }
}
